package cn.edu.sdjzu.xg11.dao;

import java.util.Collection;
import java.util.TreeSet;

import org.springframework.stereotype.Repository;

import cn.edu.sdjzu.xg11.domain.ProjectType;
@Repository
public final class ProjectTypeDao {
	private static Collection<ProjectType> projectTypes;
	static{
		projectTypes = new TreeSet<ProjectType>();
		ProjectType design = new ProjectType(1,"应用研究","01","");
		projectTypes.add(design);
		projectTypes.add(new ProjectType(2,"理论研究","02",""));
		
	}
	public Collection<ProjectType> getProjectTypes(){
		return ProjectTypeDao.projectTypes;
	}
	
	public ProjectType getProjectType(Integer id){
		ProjectType desiredProjectType = null;
		for (ProjectType projectType : projectTypes) {
			if(id.equals(projectType.getId())){
				desiredProjectType =  projectType; 
			}
		}
		return desiredProjectType;
	}
	
	public boolean updateProjectType(ProjectType projectType){
		projectTypes.remove(projectType);
		return projectTypes.add(projectType);		
	}
	
	public boolean addProjectType(ProjectType projectType){
		return projectTypes.add(projectType);		
	}

	public boolean deleteProjectType(Integer id){
		ProjectType projectType = this.getProjectType(id);
		return this.deleteProjectType(projectType);
	}
	
	public boolean deleteProjectType(ProjectType projectType){
		return projectTypes.remove(projectType);
	}
	
	public static void main(String[] args){
		ProjectTypeDao dao = new ProjectTypeDao();
		Collection<ProjectType> projectTypes = dao.getProjectTypes();
		display(projectTypes);		
	}

	private static void display(Collection<ProjectType> projectTypes) {
		for (ProjectType projectType : projectTypes) {
			System.out.println(projectType);
		}
	}
}
